package xx.iverson.navigation_manager.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import xx.iverson.navigation_manager.entity.SiteConfig;
import xx.iverson.navigation_manager.mapper.SiteConfigMapper;
import xx.iverson.navigation_manager.service.SiteConfigService;

/**
 * xx.iverson.navigation_manager.service.impl.SiteConfigServiceImpl
 * 描述：
 * on 2025/9/11-下午4:24
 *
 * @author weijx
 */

@Service
public class SiteConfigServiceImpl implements SiteConfigService {

    @Autowired
    private SiteConfigMapper siteConfigMapper;

    @Override
    public SiteConfig getSiteConfig() {
        return siteConfigMapper.findFirst();
    }

    @Override
    public int updateSiteTitle(String title) {
        SiteConfig config = siteConfigMapper.findFirst();
        if (config == null) {
            config = new SiteConfig();
            config.setSiteTitle(title);
            // 如果表中没有记录，可以考虑插入一条新记录
            // 这里假设表中至少有一条记录
            return 0;
        }
        config.setSiteTitle(title);
        return siteConfigMapper.update(config);
    }
}
